export default {

    Trims (str) {
        return str.replace(/(^\s*)|(\s*$)/g, '')
    },
    getDateTime () {
        return (new Date()).valueOf()
    },
    generateUUID () {
        var d = new Date().getTime()
        if (window.performance && typeof window.performance.now === 'function') {
            d += performance.now() // use high-precision timer if available
        }
        var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = (d + Math.random() * 16) % 16 | 0
            d = Math.floor(d / 16)
            return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16)
        })
        return uuid
    },
    transStr (str) {
        return str.replace(/([A-Z])/g, '-$1').toLowerCase()
    },
    getDate () {
        var time = new Date()
        var y = time.getFullYear()
        var m = time.getMonth() + 1
        var d = time.getDate()
        if (m.toString().length < 2) {
            m = '0' + m
        }
        if (d.toString().length < 2) {
            d = '0' + d
        }
        return y + '/' + m + '/' + d
    },
    getDate1 () {
        var time = new Date()
        // var y = time.getFullYear()
        var m = time.getMonth() + 1
        var d = time.getDate()
        if (m.toString().length < 2) {
            m = '0' + m
        }
        if (d.toString().length < 2) {
            d = '0' + d
        }
        return d + '/' + m
    },
    getTime (tm) {
        var time = new Date(tm)
        var y = time.getFullYear()
        var m = time.getMonth() + 1
        var d = time.getDate()
        var h = time.getHours()
        var s = time.getMinutes()
        if (m.toString().length < 2) {
            m = '0' + m
        }
        if (d.toString().length < 2) {
            d = '0' + d
        }
        if (h.toString().length < 2) {
            h = '0' + h
        }
        if (s.toString().length < 2) {
            s = '0' + s
        }
        return y + '-' + m + '-' + d + ' ' + h + ':' + s
    },
    getTimes (tm) {
        var time = new Date(tm)
        // var y = time.getFullYear()
        // var m = time.getMonth() + 1
        // var d = time.getDate()
        var h = time.getHours()
        var s = time.getMinutes()
        if (h.toString().length < 2) {
            h = '0' + h
        }
        if (s.toString().length < 2) {
            s = '0' + s
        }
        return h + ':' + s
    },
    getSecond () {
        var time = new Date()
        // var y = time.getFullYear()
        var m = time.getMonth() + 1
        var d = time.getDate()
        var h = time.getHours()
        var s = time.getMinutes()
        var ss = time.getSeconds()
        if (m.toString().length < 2) {
            m = '0' + m
        }
        if (d.toString().length < 2) {
            d = '0' + d
        }
        if (h.toString().length < 2) {
            h = '0' + h
        }
        if (s.toString().length < 2) {
            s = '0' + s
        }
        if (ss.toString().length < 2) {
            ss = '0' + ss
        }
        // return y + '-' + m + '-' + d + ' ' + h + ':' + s + ':' + ss
        return h + ':' + s + ':' + ss
    },
    getNowFormatDate () {
        var date = new Date()
        var seperator1 = '-'
        var month = date.getMonth() + 1
        var strDate = date.getDate()
        if (month >= 1 && month <= 9) {
            month = '0' + month
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = '0' + strDate
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        return currentdate
    },
    getNowFormatDates (type) {
        var time = new Date()
        var seperator1 = '-'
        var seperator2 = ':'
        var y = time.getFullYear()
        var m = time.getMonth() + 1
        var d = time.getDate()
        var h = time.getHours()
        var s = time.getMinutes()
        var ss = time.getSeconds()
        var currentdate = ''
        if (m.toString().length < 2) {
            m = '0' + m
        }
        if (d.toString().length < 2) {
            d = '0' + d
        }
        if (h.toString().length < 2) {
            h = '0' + h
        }
        if (s.toString().length < 2) {
            s = '0' + s
        }
        if (ss.toString().length < 2) {
            ss = '0' + ss
        }
        if (type === 'yyyy-MM-dd HH:mm:ss') {
            currentdate = y + seperator1 + m + seperator1 + d + ' ' + h + seperator2 + s + seperator2 + ss
        }
        if (type === 'yyyy年MM月dd日 HH时mm分ss秒') {
            currentdate = y + '年' + m + '月' + d + '日' + ' ' + h + '时' + s + '分' + ss + '秒'
        }
        if (type === 'yyyy年MM月dd日 HH时mm分') {
            currentdate = y + '年' + m + '月' + d + '日' + ' ' + h + '时' + s + '分'
        }
        return currentdate
    }
}
